package com.tjw.ec.upms.controller;

import com.tjw.ec.common.core.util.PageUtils;
import com.tjw.ec.common.core.util.R;
import com.tjw.ec.upms.api.entity.UserAccountEntity;
import com.tjw.ec.upms.service.UserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 控制动作层： 用户登陆信息表
 *
 * @author T-junwen
 * @email t-junwen@foxmail.com
 * @date 2019-07-27 17:28:58
 */
@RestController
@RequestMapping("useraccount")
public class UserAccountController {

    @Autowired
    private UserAccountService userAccountService;

    /**
     * @Title: 根据账号查询用户账户信息
     * @Param: [username]
     * @return: com.tjw.ec.common.core.util.Response<com.tjw.ec.upms.api.entity.UserAccountEntity>
     * @Author: 田俊文
     * @Date: 2019/8/2 13:41
     * @Throws:
     */
    @GetMapping("/getUserAccountByUsername/{username}")
    public R getUserAccountByUsername(@PathVariable("username") String username){
        UserAccountEntity userAccountEntity =  userAccountService.getUserAccountByUsername(username);
        return R.data(userAccountEntity);
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = userAccountService.queryPage(params);
        return R.data(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{userId}")
    public R info(@PathVariable("userId") String userId) {
            UserAccountEntity userAccount = userAccountService.getById(userId);
        return R.data(userAccount);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody UserAccountEntity userAccount) {
            userAccountService.save(userAccount);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody UserAccountEntity userAccount) {
            userAccountService.updateById(userAccount);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestParam String[]ids) {
            userAccountService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
